package com.cssw.fyzb.tps.service.im;

import com.cssw.fyzb.tps.service.im.common.ImHttpComm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Jian Qin.
 */
@Service
public class AccountServiceImpl implements AccountService{
    @Autowired
    private ImHttpComm imHttpComm;

    @Override
    public ImHttpComm.ImResult accountImport(String identifier, String nick, String faceUrl) {
        Map<String, Object> params = new HashMap<>();
        params.put("Identifier", identifier);
        params.put("Nick", nick);
        params.put("FaceUrl", faceUrl);
        return imHttpComm.post("/im_open_login_svc/account_import", params);
    }

    @Override
    public ImHttpComm.ImResult accountDelete(String[] userIds) {
        Map<String, Object> params = new HashMap<>();
        List<Map<String, String>> userList = new ArrayList<>();
        for(String userId : userIds){
            Map<String, String> m = new HashMap<>();
            m.put("UserID", userId);
            userList.add(m);
        }
        params.put("DeleteItem", userList);
        return imHttpComm.post("/im_open_login_svc/account_delete", params);
    }

    @Override
    public ImHttpComm.ImResult accountCheck(String[] userIds) {
        Map<String, Object> params = new HashMap<>();
        List<Map<String, String>> userList = new ArrayList<>();
        for(String userId : userIds){
            Map<String, String> m = new HashMap<>();
            m.put("UserID", userId);
            userList.add(m);
        }
        params.put("CheckItem", userList);
        return imHttpComm.post("/im_open_login_svc/account_check", params);
    }

    @Override
    public ImHttpComm.ImResult accountKick(String identifier) {
        Map<String, Object> params = new HashMap<>();
        params.put("Identifier", identifier);
        return imHttpComm.post("/im_open_login_svc/kick", params);
    }

    @Override
    public ImHttpComm.ImResult accountQueryState(String[] userIds, String isNeedDetail) {
        Map<String, Object> params = new HashMap<>();
        List<String> userList = new ArrayList<>();
        for(String userId : userIds){
            userList.add(userId);
        }
        params.put("To_Account", userList);
        params.put("IsNeedDetail", "1".equals(isNeedDetail) ? 1 : 0);
        return imHttpComm.post("/openim/querystate", params);
    }
}
